package data
{
	
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.graphics.SolidColor;
	
	import spark.components.BorderContainer;
	import spark.components.Button;
	
	public class LineLayer extends BorderContainer
	{
		
		private var deleteBt:Button
		private var deleteBt_hide_timer:Timer
		private var scp:MyBorderContainer
		private var _startBC:MyBorderContainer;
		private var _finishBC:MyBorderContainer;
		
		public function LineLayer(_scp:MyBorderContainer)
		{
			super();
			scp=_scp;
			this.width=70;
			this.height=70;
			this.setStyle("borderAlpha",0);
			this.backgroundFill=new SolidColor(0,0);
			
			
			
			
			
			
			
			
		}
		
		public function deleteBt_setting():void{
			// 라인삭제버튼
			trace("deleteBt_setting");
			deleteBt=new Button();
			deleteBt.label="Delete";
			addElement(deleteBt);
			deleteBt.visible=false;
			
			this.addEventListener(MouseEvent.MOUSE_OVER,mouse_hdl);
			this.addEventListener(MouseEvent.MOUSE_OUT,mouse_hdl);
			
			deleteBt.addEventListener(MouseEvent.MOUSE_OVER,deleteBt_hdl);
			deleteBt.addEventListener(MouseEvent.MOUSE_OUT,deleteBt_hdl);
			deleteBt.addEventListener(MouseEvent.CLICK,deleteBt_hdl);
			
			deleteBt_hide_timer=new Timer(300);
			deleteBt_hide_timer.addEventListener(TimerEvent.TIMER,deleteBt_hide_hdl);
			
		}
		

		public function get finishBC():MyBorderContainer
		{
			return _finishBC;
		}

		public function set finishBC(value:MyBorderContainer):void
		{
			_finishBC = value;
		}

		public function get startBC():MyBorderContainer
		{
			return _startBC;
		}

		public function set startBC(value:MyBorderContainer):void
		{
			_startBC = value;
		}

		protected function deleteBt_hide_hdl(event:TimerEvent):void
		{
			deleteBt.visible=false;
		}
		
		protected function deleteBt_hdl(event:MouseEvent):void
		{
			if(event.type==MouseEvent.MOUSE_OVER){
//				deleteBt.visible=true;
				deleteBt_hide_timer.stop()
				return;
			}
			if(event.type==MouseEvent.MOUSE_OUT){
				deleteBt_hide_timer.start()
				return;
			}
			if(event.type==MouseEvent.CLICK){
				deleteBt.visible=false;
				this.graphics.clear();
				scp.deleteLineLayer(this);
				
				//startBc에서는 nBc에서.. finishBc에서는 pBc에서 각 아이템들을 지워준다.
				
				//startBc의 pBc중 finishBc 빼기
				var i:uint=0;
				for(i=0;i< _startBC.nBc.length;++i){
					if(_startBC.nBc[i]==_finishBC){
						_startBC.nBc.splice(i,1);
						break;
					}
				}
				
				//finishBc의 pBc중 startBc 빼기
				for(i=0;i< _finishBC.pBc.length;++i){
					if(_finishBC.pBc[i]==_startBC){
						_finishBC.pBc.splice(i,1);
						break;
					}
				}
				
				
				
				return;
			}
			
		}
		
		protected function mouse_hdl(event:MouseEvent):void
		{
			if(event.type==MouseEvent.MOUSE_OVER){
				deleteBt.visible=true;
				deleteBt.x = this.mouseX-deleteBt.width/2;
				deleteBt.y = this.mouseY-deleteBt.height/2;
				return;
			}
			if(event.type==MouseEvent.MOUSE_OVER){
				deleteBt_hide_timer.start();
				return;
			}
		}		
		
	}
}